/**
 * 
 */
package com.ms.service.module.fish;

import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.game.gmtool.ISlotGameServerActionToGMTool;
import com.ms.game.slot.base.message.SGmtoolCleanGameSeatStatusRequest;
import com.ms.service.module.account.message.SSessionCloseNotify;
import com.ms.service.module.fish.game.FishGlobal;
import com.ms.service.module.fish.message.FishMsgType;
import com.ms.service.module.fish.message.FishRequestWrap;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.annotations.MessageType;
import com.xpec.c4.service.common.BaseMessageAction;
import com.xpec.c4.service.contexts.Contexts;
import com.xpec.c4.service.module.BasicServiceModule;

/**
 * 百家樂消息接收類別
 * 
 * @author TW15010
 */
public class FishAction extends BaseMessageAction implements ISlotGameServerActionToGMTool
{
	/** log4j object */
	private static final Log log = LogFactory.getLog(FishAction.class);

	/**
	 * 取得收消息的 module processor instance
	 * 
	 * @return
	 */
	private FishProcessor getProc() {
		BasicServiceModule module = getModule();
		if (!(module instanceof FishGameModule)) {
			if (log.isErrorEnabled()) {
				log.error(GameUtility.getCurMethodName() + ": get game module type is invalid.");
			}
			return null;
		}

		FishGameModule bacrModule = (FishGameModule) module;

		FishProcessor proc = bacrModule.getProc();

		return proc;
	}

	@MessageType(typeCode = MessageTypes.C_FISH_ACTION_DISPATCH)
	public void dispatcher(byte[] bytes) {
		FishRequestWrap request = new FishRequestWrap(ByteBuffer.wrap(bytes));
		request.setSessionId(Contexts.getSessionID());
		FishProcessor proc = getProc();
		
		int cmd = request.getInt();
		
		MySession session = FishGlobal.getSessionBySid(Contexts.getSessionID());
		switch (cmd) {
		case FishMsgType.ACTION_100:
			proc.enterRoom(request);
			break;
		case FishMsgType.ACTION_110:
			proc.preEnter(session, request);
			break;
		case FishMsgType.ACTION_111:
			proc.enterFishGame(session,request);
			break;
		case FishMsgType.ACTION_118:
			proc.outFishGame(session,request);
			break;
		case FishMsgType.ACTION_200:
			proc.fire(session,request);
			break;
		case FishMsgType.ACTION_202:
			proc.catchFish(session,request);
			break;
		case FishMsgType.ACTION_203:
			proc.changBattery(session,request);
			break;
		case FishMsgType.ACTION_204:
			proc.changeRate(session,request);
			break;
		case FishMsgType.ACTION_206:
			proc.lockFire(session,request);
			break;
		case FishMsgType.ACTION_207:
			proc.catchMultFish(session,request);
			break;
		case FishMsgType.ACTION_208:
			proc.laba(session,request);
			break;
		case FishMsgType.ACTION_209:
			proc.roomRewards(session,request);
			break;
		case FishMsgType.ACTION_300:
			proc.loadConf(session,request);
			break;

		default:
			break;
		}
		
	}
	
	@MessageType(typeCode = MessageTypes.S_SESSION_CLOSE_NOTIFY)
	public void revDisConnect(SSessionCloseNotify request) {
		this.getProc().revDisConnect(request);
	}

	@Override
	@MessageType(typeCode = MessageTypes.S_GMTOOL_CLEAN_GAME_SEAT_STATUS)
	public void revGmtoolCleanGameSeatStatus(
			SGmtoolCleanGameSeatStatusRequest request) 
	{
		getProc().revGmtoolCleanGameSeatStatus(request);
	}
	
	
}
